package dame2;

public class MyCircularqueue {   //循环队列
    public int front;
    public int rear;
    public int[] elem;

    public MyCircularqueue(int k) {
        this.elem = new int[k+1];
    }
    public boolean enQueue(int value){   //入队列
        if (ifFull()){
            return false;
        }
        elem[rear] = value;
        rear = (rear+1)%elem.length;
        return true;
    }
    public boolean deQueue(){   //
        if (isEmpty()){
            return false;
        }
        front = (front+1)%elem.length;
        return true;
    }
    public int Float(){    //得到对头元素
        if (isEmpty()){
            return -1;
        }
        return elem[front];
    }
    public int Rear(){
        if (isEmpty()){
            return -1;
        }
        int indead = (rear==0) ?elem.length-1 :rear-1;
        return elem[indead];
    }
    public boolean isEmpty(){   //判断队列是否为空
        return rear==front;
    }
    public boolean ifFull(){     //判断队列是否满
        return (rear+1)%elem.length==front;
    }
}
